package com.bz.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bz.item.service.ItemParamItemService;
import com.bz.mapper.TbItemParamItemMapper;
import com.bz.pojo.TbItemParamItem;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ItemParamItemServiceImpl extends ServiceImpl<TbItemParamItemMapper, TbItemParamItem> implements ItemParamItemService {


    @Override
    //@LcnTransaction
    public Integer insertTbItemParamItem(TbItemParamItem tbItemParamItem) {
        return this.baseMapper.insert(tbItemParamItem);
    }

    @Override
    //@LcnTransaction
    public Integer updateTbItemParamItem(TbItemParamItem tbItemParamItem) {
        UpdateWrapper<TbItemParamItem> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(tbItemParamItem.getItemId() != null,TbItemParamItem::getItemId,tbItemParamItem.getItemId());
        tbItemParamItem.setUpdated(new Date());
        return this.baseMapper.update(tbItemParamItem,updateWrapper);
    }

    @Override
    public TbItemParamItem selectTbItemParamItemByItemId(Long itemId) {
        QueryWrapper<TbItemParamItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(itemId != null,TbItemParamItem::getItemId,itemId);
        return this.baseMapper.selectOne(queryWrapper);
    }
}
